package com.itheima.d3_annotation;

import org.junit.Test;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/*
    目标：掌握注解的解析。

    AnnotatedElement接口提供了解析注解的方法
        public Annotation[] getDeclaredAnnotations()	获取当前对象上面的注解。
        public T getDeclaredAnnotation(Class<T> annotationClass)	获取指定的注解对象
        public boolean isAnnotationPresent(Class<Annotation> annotationClass)	判断当前对象上是否存在某个注解
 */
public class AnnotationTest3 {
    @Test
    public void parseClass() throws Exception {
        Class clazz = bookDemo.class;
        Method show = clazz.getDeclaredMethod("show");
        boolean annotationPresent = show.isAnnotationPresent(book.class);
        if(annotationPresent){
            book declaredAnnotation = show.getDeclaredAnnotation(book.class);
            System.out.println(declaredAnnotation.name());
            System.out.println(declaredAnnotation.price());


        }



    }

    @Test
    public void parseMethod() throws Exception {
        Class clazz = bookDemo.class;
        if(clazz.isAnnotationPresent(book.class)){
            book bookDemo1 = (book) clazz.getDeclaredAnnotation(book.class);
            System.out.println(bookDemo1.name());
            System.out.println(bookDemo1.price());


        }
    }
}
